package com.xgz.entity;

import java.lang.reflect.Constructor;

public class Test3 {
    public static void main(String[] args) {
        Class<Animal> animalClass = Animal.class;
        //获取所有的共有的构造方法
        Constructor<?>[] constructors = animalClass.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println("所有的共有的构造方法: " + constructor);
        }

        try {
            //获取指定的参数类型的构造方法
            Constructor<Animal> constructor = animalClass.getConstructor(String.class, Integer.class, String.class, Integer.class);
            System.out.println("constructor = " + constructor);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

    }
}
